import isPrime from './isPrime';

export default class NumberTimer{
    constructor(duration = 500) {
        this.duration = duration;
        this.number = 1;
        this.NumberGenerator = null; // 生成Number的回调函数
        this.timer = null;
    }
    start() { 
       if (this.timer) return;
       this.timer =  setInterval(() => {
           this.NumberGenerator && this.NumberGenerator(this.number, isPrime(this.number));
           this.number++;
        }, this.duration);
    };
    stop() { 
        clearInterval(this.timer)
        this.timer = null;
    };
}